from django.db import models


class TopBar(models.Model):
    name = models.CharField('名称', max_length=32)
    icon = models.CharField('图标', max_length=255, blank=True, null=True, default="")
    addtime = models.DateTimeField("添加时间", auto_now=True)

    def __str__(self):
        return str(self.id) + "-" + self.name
    
    class Meta:
        db_table = "top_bar"
        verbose_name_plural = verbose_name = "置顶标题"

class Shop(models.Model):
    name = models.CharField("店铺名称", max_length=32)
    logo = models.ImageField("店铺LOGO", upload_to="img/shop/logo")
    sale_num = models.PositiveIntegerField("在售商品数量", default=0)
    shop_img = models.ImageField("店铺图片", upload_to="img/shop/")
    shop_recommend_img = models.ImageField("店铺推荐图片", upload_to="img/shop/")
    addtime = models.DateTimeField("添加时间", auto_now=True)
    def __str__(self):
        return str(self.id) + "-" + self.name
    class Meta:
        db_table = "shop"
        verbose_name_plural = verbose_name = "店铺"

class Brand(models.Model):
    name = models.CharField("品牌名称", max_length=32)
    logo = models.ImageField("品牌LOGO", upload_to="img/shop/logo")
    addtime = models.DateTimeField("添加时间", auto_now=True)
    def __str__(self):
        return str(self.id) + "-" + self.name
    class Meta:
        db_table = "brand"
        verbose_name_plural = verbose_name = "品牌"

class PrimaryGoodsType(models.Model):
    name = models.CharField("分类名称", max_length=32)
    addtime = models.DateTimeField("添加时间", auto_now=True)
    def __str__(self):
        return str(self.id) + "-" + self.name
    class Meta:
        db_table = "primary_goods"
        verbose_name_plural = verbose_name = "一级分类"

class SecondaryGoodsType(models.Model):
    name = models.CharField("分类名称", max_length=32)
    img = models.ImageField("图片", upload_to="img/secondary/")
    primary = models.PositiveIntegerField("一级分类名称", default=0)
    addtime = models.DateTimeField("添加时间", auto_now=True)
    def __str__(self):
        return str(self.id) + "-" + self.name
    class Meta:
        db_table = "secondary_goods"
        verbose_name_plural = verbose_name = "二级分类"

class Goods(models.Model):
    name = models.CharField("名称", max_length=255)
    img = models.ImageField("图片", upload_to="img/detail/thumbnail/")
    detail = models.TextField("详解", default="")
    detail_img = models.ImageField("详解图片", upload_to="img/detail/", blank=True, null=True)
    pprice = models.PositiveIntegerField("现价", default=0)
    oprice = models.PositiveIntegerField("原价", default=0)
    discount = models.CharField("折扣", max_length=3, blank=True, null=True, default="")
    secondary = models.PositiveIntegerField("二级分类名称", default=0)
    shop = models.PositiveIntegerField("所属店铺", default=0)
    brand = models.PositiveIntegerField("所属品牌", default=0)
    addtime = models.DateTimeField("添加时间", auto_now=True)
    def __str__(self):
        return str(self.id) + "-" + self.name
    class Meta:
        db_table = "goods"
        verbose_name_plural = verbose_name = "商品"

# 颜色属性值表
class ColorGoodsAttribute(models.Model):
    name = models.CharField("颜色", max_length=8)
    def __str__(self):
        return str(self.id) + "-" + self.name
    class Meta:
        db_table = "color"
        verbose_name_plural = verbose_name = "颜色"

# 尺寸属性值表
class SizeGoodsAttribute(models.Model):
    name = models.CharField("尺寸", max_length=8)
    def __str__(self):
        return str(self.id) + "-" + self.name
    class Meta:
        db_table = "size"
        verbose_name_plural = verbose_name = "尺寸"

class SPU(models.Model):
    img = models.ImageField("图片", upload_to="img/spu/")
    color = models.PositiveIntegerField("颜色", default=0)
    size = models.PositiveIntegerField("尺寸", default=0)
    price = models.IntegerField("价格")
    inventory = models.IntegerField("库存")
    class Meta:
        db_table = "spu"
        verbose_name_plural = verbose_name = "SPU"

class Comments(models.Model):
    name = models.CharField("昵称", max_length=255)
    content = models.TextField("评论内容", default="")
    def __str__(self):
        return str(self.id) + "-" + self.name
    class Meta:
        db_table = "comments"
        verbose_name_plural = verbose_name = "评论"

class Swiper(models.Model):
    name = models.CharField("轮播名称", max_length=32)
    img = models.ImageField("图片", upload_to="img/swiper")
    order = models.PositiveIntegerField("排序", default=1)
    def __str__(self):
        return str(self.id) + "-" + self.name
    class Meta:
        db_table = "swiper"
        verbose_name_plural = verbose_name = "轮播"